package app.controller.core
{
	import app.AppConstants;
	import app.model.flare.proxies.FlareDataProxy;
	import app.model.flare.vos.ActionVO;
	import app.model.flare.vos.StateVO;
	
	import mx.collections.IList;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;

	public class DecodeToAS3Cmd extends SimpleCommand
	{
		override public function execute(notification:INotification):void{
			var s:String = "package app{\r\tpublic class StateConstants{\r\r",
				state_names:String = toAS3StateConsts( FlareDataProxy(facade.retrieveProxy(FlareDataProxy.NAME)).stateList ),
				action_names:String = toAS3ActionConsts( FlareDataProxy(facade.retrieveProxy(FlareDataProxy.NAME)).actionList ),
				state_declare:String = FlareDataProxy(facade.retrieveProxy(FlareDataProxy.NAME)).toXMLString();
			s += state_names +"\r";
			s += action_names +"\r"
			s += "\t\tpublic static const STATE_DECLARATION:XML = \r"
			
			s +=  state_declare + "\r";
			s += "\t}\r}"
			sendNotification(AppConstants.SHOW_TEXT_FORM, null, s);
		}
		
		private function toAS3StateConsts( states:IList ):String{
			var s:String = "";
			for each (var state:StateVO in states){
				s += "\t\tpublic static const "+state.nameCapsSlug+":String = \"" + state.nameSlug + "\";\r";
				if(state.changed)s += "\t\tpublic static const "+state.changedCapsSlug+":String = \"" + state.changedSlug + "\";\r";
				if(state.entering)s += "\t\tpublic static const "+state.enteringCapsSlug+":String = \"" + state.enteringSlug + "\";\r";
				if(state.exiting)s += "\t\tpublic static const "+state.exitingCapsSlug+":String = \"" + state.exitingSlug + "\";\r";
				s += "\r";
			}
			return s;
		}
		
		private function toAS3ActionConsts( actions:IList ):String{
			var s:String = "";
			for each (var action:ActionVO in actions){
				s += "\t\tpublic static const "+action.capsSlug+":String = '" + action.slug + "';\r";
				//s += "\r";
			}
			return s;
		}
		
		
	}
}